package org.tof.hotel.jdbc;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.tof.hotel.dao.AdministratorDaoImpl;
import org.tof.hotel.dto.AdministratorDTO;

import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class Driver {
    static Logger logger = Logger.getLogger(Driver.class.getName());


    public static void main(String[] args) {
        BasicConfigurator.configure();
        Properties dbProps = new Properties();
        try {
            dbProps.load(Driver.class.getResourceAsStream("/org/tof/hotel/db.properties"));
            Class.forName(dbProps.getProperty("driver"));

            Connection conn = DriverManager.getConnection(dbProps.getProperty("url"),dbProps.getProperty("user"),dbProps.getProperty("password"));
            Statement stat = conn.createStatement();
            ResultSet resultSet = stat.executeQuery("select * from Customer");

            for(int i = 1; i <= resultSet.getMetaData().getColumnCount() ; i++){
                System.out.println("col " + i + ": " + resultSet.getMetaData().getColumnName(i));
            }

        } catch (IOException e) {
            logger.error(e.toString(), e);
        } catch (ClassNotFoundException e) {
            logger.error(e.toString(), e);
        } catch (SQLException e) {
            logger.error(e.toString(), e);
        }

        AdministratorDTO dto = new AdministratorDTO("Russell","Crow","000999001","rcrow@gmail.com","Los Angeles",0);
        AdministratorDaoImpl dao = null;
        try {
            dao = new AdministratorDaoImpl();
            dao.insert(dto);
            //cc
        } catch (SQLException e) {
            logger.error("dao error!", e);
        } catch (ClassNotFoundException e) {
            logger.error(e.toString(), e);
        } catch (IOException e) {
            logger.error(e.toString(), e);
        }

    }
}
